package com.appkubes.mall.restful.application.goods.rent.dao;

import com.appkubes.mall.core.dao.BaseMallGoodsRentDao;
import com.appkubes.mall.restful.application.goods.goods.entity.dto.MallGoodsRentDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface GoodsRentDao extends BaseMallGoodsRentDao {

    @Select("SELECT good.goods_key, good.cat_key, good.name, good.unit, good.weight, good.pic, good.tags, good.sort, (good.virtual_stock+good.real_stock) as sotck" +
            ",good.subheading, COALESCE(rent.cost_per_period, good.price) as price, rent.period_type FROM mall_goods as good" +
            " LEFT JOIN mall_goods_rent as rent ON good.goods_key=rent.goods_key" +
            " WHERE good.app_key=#{appKey} AND (good.cat_key=#{categoryKey} OR good.cate_list like '%${categoryKey}%')" +
            " AND good.state=1" +
            " ORDER BY good.`sort` ASC ")
    List<MallGoodsRentDTO> selectGoods(@Param("categoryKey") String categoryKey, @Param("appKey") String appKey);
}
